var app = new Vue({
    el: '#app',
    data: {
        pagination: {//分页相关模型数据
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的记录数
            total: 0,//总记录数
            stationId: null, //查询条件
            position: null, //查询条件
            deviceTypeId: null,
            lineId: null,
        },
        editTitle: null,
        fanDetailVo: null,
        currentStatus: null,
        activeName: 'getStatus',
        dialogTitle: null,
        isOld3Channel: false,
        lowValue1: null,
        highValue1: null,
        lowValue2: null,
        highValue2: null,
        lowValue3: null,
        highValue3: null,
        startTime1: null,
        endTime1: null,
        startTime2: null,
        endTime2: null,
        startTime3: null,
        endTime3: null,
        deviceVo: {}, // 点击操作按钮时保存的实体
        operationFormVisible: false, // 接地电阻操作的dialog
        operationFormVisible_Tem: false , // 温湿度计操作的Dialog 
        multipleSelection: [],
        channelNumber: 1,
        channelNumberList: [1, 2, 3, 4, 5, 6],
        dataList: [],//当前页要展示的分页列表数据
        formData: {},//表单数据
        dialogFormVisible: false,//增加表单是否可见
        rules: {//校验规则
            stationId: [{required: true, message: '终端ID为必填项', trigger: 'blur'},
                {pattern: '[^ \x22]+', message: '终端ID不能为空'}],
            position: [{required: true, message: '站点名称为必填项', trigger: 'blur'},
                {pattern: '[^ \x22]+', message: '站点名称不能为空'}],
            lineId: [{required: true, message: '生产线为必填项', trigger: 'blur'}],
            deviceTypeId: [{required: true, message: '终端类型为必填项', trigger: 'blur'}],
            gatewayId: [{required: true, message: '网关为必填项', trigger: 'blur'}]
        },
        deviceTypes: null, // 终端类型列表
        gateways: null, // 网关列表
        channelTypes: null, // 通道类型列表
        channels: [], // 辅助的中间变量
        lines: null, // 生产线列表
        value: '',
        operationFormVisible_fan: false, // 离子操作dialog是否可见
        fanLevel: 1, // 离子风扇的档位
        fanLevels: [1, 2, 3, 4, 5], // 离子风扇档位列表
        fanStartTime1: null, // 离子风扇的自启动时间 早上
        fanStartTime2: null, // 离子风扇的自启动时间 下午
        fanStartTime3: null, // 离子风扇的自启动时间 晚上
        fanSleepTime1: null, // 离子风扇的休眠时间 上午
        fanSleepTime2: null, // 离子风扇的休眠时间 下午
        fanSleepTime3: null, // 离子风扇的休眠时间 晚上
        fanCleanTime: null, // 离子风扇的清扫时间
        maintainTime: null, // 离子风扇的保养时间
        lowDYValue: null, // 平衡电压下限
        highDYValue: null, // 平衡电压上限
        lowFDZDYValue: null, // 放电针电压下限
        highFDZDYValue: null, // 放电针电压下限
        isNewFan: false,
        line_radio: '1',
        change_gatewayId: null,
        // ============================
        temLower: null,
        temUpper: null,
        humiLower: null,
        humiUpper: null,
        temDetail: {
            tem: null ,
            humi: null
        },
        // ============================
        operationFormVisible_NewDZY: false,
        dzyDetailNew: null ,
        channelOnDT: null ,
        channelTypeList: null ,
        channelTypeSel: [
            { id: "01", label: 'ESD手环' },
            { id: "02", label: '台垫接地' },
            { id: "03", label: '设备接地' }
        ],
        redClock: null ,
        // ============================
        operationFormVisible_chenAi: false,
        dustStatus: null ,
        // dustParameters: null ,
        dustWorkMods: [
            {
                id: 0,
                label: '连续模式'
            },
            {
                id: 1,
                label: '间歇模式'
            }
        ],
        sortFlag: false ,
        sortLineId: null,
        sortDeviceList: null,
        sortLength: null,
        isMOM1: false ,
        isMOM2: false ,
        channelValue: null
    },
    //钩子函数，VUE对象初始化完成后自动执行
    created() {
        axios.get("/deviceType/selectAll").then((res) => {
            this.deviceTypes = res.data.data;
        });
        axios.get("/gateway/getAll").then((res) => {
            this.gateways = res.data.data;
        });
        axios.get("/line/listAll").then((res) => {
            this.lines = res.data.data;
        });
        axios.get("/channelType/listAll").then((res) => {
            this.channelTypes = res.data.data;
        });
        for (let i = 0; i < 6; i++) {
            this.channels.push({
                channelTypeId: null,
                enabled: true,
                position: null ,
                deviceType: null
            });
        }
        this.findPage();
    },
    watch: {
        activeName: function (newValue, oldValue) {
            this.line_radio = "1";
        }
    },
    methods: {
        findPage1() {
            this.pagination.currentPage = 1;
            this.findPage();
        },
        deviceGetChannelClass(enabled) {
            return enabled ? 'channelTypeEnabled' : 'channelTypeDisabled';
        },
        deviceGetChannelImg(channelTypeName) {
            if (channelTypeName === 'ESD手环') {
                return "../../images/SVG/WH0.svg";
            } else if (channelTypeName === '设备接地') {
                return "../../images/SVG/EM0.svg";
            } else if (channelTypeName === '台垫接地') {
                return "../../images/SVG/RR0.svg";
            } else if (channelTypeName === '离子风扇'){
                return "../../images/SVG/EN0.svg";
            }else if (channelTypeName === '温度计'){
                return "../../images/SVG/TE1.svg";
            }else if (channelTypeName === '湿度计'){
                return "../../images/SVG/HU0.svg";
            }else if (channelTypeName === '尘埃粒子'){
                return "../../images/SVG/CL1.svg";
            }
        },
        getChannelClass(enabled) {
            return this.deviceGetChannelClass(enabled);
        },
        getChannelImg(channelTypeName) {
            return this.deviceGetChannelImg(channelTypeName);
        },
        // TODO ==== 离子风扇操作方法::开始 ====
        fanGetStatus() {
            $axios({
                url: '/fan/search/getDetail',
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.fanDetailVo = res.data;
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleFanSwitch(value) {
            if (this.line_radio === "2") {
                $axios({
                    url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                    method: 'get',
                    params: null
                }).then((res) => {
                    if (res.code === 0) {
                        let deviceVoss = res.data;
                        for (let i = 0; i < deviceVoss.length; i++) {
                            handleFanSwitch1(value , deviceVoss[i]);
                        }
                    } else {
                        this.$message.error("查询失败！！");
                    }
                })
            } else {
                handleFanSwitch1(value , this.deviceVo);
            }
        },
        handleFanLevelSwitch(value) {
            if (this.line_radio === "2") {
                $axios({
                    url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                    method: 'get',
                    params: null
                }).then((res) => {
                    if (res.code === 0) {
                        let deviceVoss = res.data;
                        for (let i = 0; i < deviceVoss.length; i++) {
                            handleFanLevelSwitch1(value , deviceVoss[i])
                        }
                    } else {
                        this.$message.error("查询失败！！");
                    }
                })
            } else {
                handleFanLevelSwitch1(value , this.deviceVo);
            }
        },
        fanLevelHandle() {
            if (this.line_radio === "2") {
                $axios({
                    url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                    method: 'get',
                    params: null
                }).then((res) => {
                    if (res.code === 0) {
                        let deviceVoss = res.data;
                        for (let i = 0; i < deviceVoss.length; i++) {
                            fanLevelHandle1(deviceVoss[i])
                        }
                    } else {
                        this.$message.error("查询失败！！");
                    }
                })
            } else {
                fanLevelHandle1(this.deviceVo);
            }
        },
        fanHandleTime() {
            if (this.line_radio === "2") {
                $axios({
                    url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                    method: 'get',
                    params: null
                }).then((res) => {
                    if (res.code === 0) {
                        let deviceVoss = res.data;
                        for (let i = 0; i < deviceVoss.length; i++) {
                            fanHandleTime1(deviceVoss[i])
                        }
                    } else {
                        this.$message.error("查询失败！！");
                    }
                })
            } else {
                fanHandleTime1(this.deviceVo);
            }
        },
        fanGetStartTime(value) {
            $axios({
                url: "/fan/search/getStartTime/" + value,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    if(value=="02"){
                        this.fanStartTime1 = new Date("2016-09-10T" + res.data.timeStr);
                    }else if(value == "03"){
                        this.fanStartTime2 = new Date("2016-09-10T" + res.data.timeStr);
                    }else if(value == "04"){
                        this.fanStartTime3 = new Date("2016-09-10T" + res.data.timeStr);
                    }
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetStartTime(value) {
            let h , m , s ;
            if(value == "02"){
                if(this.fanStartTime1 === null || this.fanStartTime1 === '' ){
                    this.$message({ type: 'error', message: "请正确选择自启动时间！！" });
                    return;
                }
                h = this.fanStartTime1.getHours();  m = this.fanStartTime1.getMinutes();  s = this.fanStartTime1.getSeconds();
            }else if(value == "03"){
                if(this.fanStartTime2 === null || this.fanStartTime2 === '' ){
                    this.$message({ type: 'error', message: "请正确选择自启动时间！！" });
                    return;
                }
                h = this.fanStartTime2.getHours();  m = this.fanStartTime2.getMinutes();  s = this.fanStartTime2.getSeconds();
            }else if(value == "04"){
                if(this.fanStartTime3 === null || this.fanStartTime3 === '' ){
                    this.$message({ type: 'error', message: "请正确选择自启动时间！！" });
                    return;
                }
                h = this.fanStartTime3.getHours();  m = this.fanStartTime3.getMinutes();  s = this.fanStartTime3.getSeconds();
            }
            let timeStr = h + "-" + m + "-" + s;
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的自启动时间吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetStartTime1(value , timeStr, deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的自启动时间吗？", "提示", {
                    type: 'warning'
                }).then(() => {
                    fanSetStartTime1( value , timeStr, this.deviceVo);
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        fanGetSleepTime(value) {
            $axios({
                url: "/fan/search/getSleepTime/" + value,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    if(value=="05"){
                        this.fanSleepTime1 = new Date("2016-09-10T" + res.data.timeStr);
                    }else if(value == "06"){
                        this.fanSleepTime2 = new Date("2016-09-10T" + res.data.timeStr);
                    }else if(value == "07"){
                        this.fanSleepTime3 = new Date("2016-09-10T" + res.data.timeStr);
                    }
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetSleepTime(value) {
            let h , m , s ;
            if(value == "05"){
                if (this.fanSleepTime1 === null || this.fanSleepTime1 === '') {
                    this.$message({ type: 'error', message: "请正确选择休眠时间！！" });
                    return;
                }
                h = this.fanSleepTime1.getHours(); m = this.fanSleepTime1.getMinutes(); s = this.fanSleepTime1.getSeconds(); 
            }else if(value == "06"){
                if (this.fanSleepTime2 === null || this.fanSleepTime2 === '') {
                    this.$message({ type: 'error', message: "请正确选择休眠时间！！" });
                    return;
                }
                h = this.fanSleepTime2.getHours(); m = this.fanSleepTime2.getMinutes(); s = this.fanSleepTime2.getSeconds(); 
            }else if(value == "07"){
                if (this.fanSleepTime3 === null || this.fanSleepTime3 === '') {
                    this.$message({ type: 'error', message: "请正确选择休眠时间！！" });
                    return;
                }
                h = this.fanSleepTime3.getHours(); m = this.fanSleepTime3.getMinutes(); s = this.fanSleepTime3.getSeconds(); 
            }
            let timeStr = h + "-" + m + "-" + s ;
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的休眠时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetSleepTime1( value, timeStr ,deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的休眠时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    fanSetSleepTime1( value, timeStr , this.deviceVo);
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        fanGetCleanTime() {
            $axios({
                url: "/fan/search/getCleanTime",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    this.fanCleanTime = new Date("2016-09-10T" + res.data.timeStr);
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetCleanTime() {
            if (this.fanCleanTime === null || this.fanCleanTime === '') {
                this.$message({ type: 'error', message: "请选择风扇清扫时间！！" });
                return;
            }
            let h = this.fanCleanTime.getHours(); // 时
            let m = this.fanCleanTime.getMinutes(); // 分
            let s = this.fanCleanTime.getSeconds(); // 秒
            let timeStr = h + "-" + m + "-" + s;
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的清扫时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetCleanTime1(timeStr , deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });

                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的清扫时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    fanSetCleanTime1(timeStr , this.deviceVo)
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        fanGetMaintainTime() {
            $axios({
                url: "/fan/search/getMaintainTime",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    this.maintainTime = res.data.hours;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetMaintainTime() {
            if (this.maintainTime === null || this.maintainTime === '') {
                this.$message({ type: 'error', message: "请选择风扇保养时间！！" });
                return;
            }
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的保养时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetMaintainTime1(deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info',  message: '操作已取消' });

                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的保养时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    fanSetMaintainTime1(this.deviceVo);
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        fanGetBalancePower() {
            $axios({
                url: "/fan/search/getVoltageLimit",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    this.lowDYValue = res.data.min;
                    this.highDYValue = res.data.max;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetBalanceDY() {
            if (this.lowDYValue === null || this.lowDYValue === ''
                || this.highDYValue === null || this.highDYValue === '') {
                this.$message({ type: 'error', message: "请正确填写平衡电压上下限！！" });
                return;
            }
            let powerStr = this.lowDYValue + "-" + this.highDYValue;
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的平衡电压吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetBalanceDY1(powerStr , deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });

                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的平衡电压吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    fanSetBalanceDY1(powerStr , this.deviceVo);
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        fanGetFDZDY() {
            $axios({
                url: "/fan/search/getPowerLimit",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.data.message });
                    this.lowFDZDYValue = res.data.min;
                    this.highFDZDYValue = res.data.max;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        fanSetFDZDY() {
            if (this.lowFDZDYValue === null || this.lowFDZDYValue === ''
                || this.highFDZDYValue === null || this.highFDZDYValue === '') {
                this.$message({ type: 'error', message: "请正确填写放电针电压上下限！！" });
                return;
            }
            let powerStr = this.lowFDZDYValue + "-" + this.highFDZDYValue;
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的放电电压吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                fanSetFDZDY1(powerStr , this.deviceVo)
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });

                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的放电电压吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    fanSetFDZDY1(powerStr , this.deviceVo)
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        handleFanXindao() {
            this.$confirm("你确定要更改终端 " + this.deviceVo.stationId + "的信道吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: "/fan/operation/setSignalChannel/" + this.change_gatewayId,
                    method: 'post',
                    data: this.deviceVo
                }).then((res) => {
                    if (res.code === 0) {
                        this.$message({ type: 'success', message: res.msg });
                        this.findPage();
                        this.operationFormVisible = false;
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            }).catch(() => {
                this.$message({ type: 'info', message: '操作已取消' });
            });
        },
        // TODO ==== 离子风扇操作方法::结束 ====
        handleGetStatus() {
            $axios({
                url: '/resistance/search/old/getDetails',
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                    this.currentStatus = res.data;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        handleGetScale() {
            $axios({
                url: '/resistance/search/old/getScale',
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                    this.lowValue1 = res.data.tdxx;
                    this.highValue1 = res.data.tdsx;
                    this.lowValue2 = res.data.rtxx;
                    this.highValue2 = res.data.rtsx;
                    this.lowValue3 = res.data.sbxx;
                    this.highValue3 = res.data.sbsx;
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        handleSetScale(channel) {
            if (channel === "11" &&
                (this.lowValue1 < 0 || this.lowValue1 > 99
                    || this.highValue1 <= 0 || this.highValue1 > 99.99 || (this.lowValue1 >= this.highValue1)
                    || this.lowValue1 === null || this.highValue1 === null
                )
            ) {
                this.$message({ type: 'error',  message: '阀值设置有误！！' });
                return;
            } else if (channel === "15" &&
                (this.lowValue2 < 0 || this.lowValue2 > 99
                    || this.highValue2 <= 0 || this.highValue2 > 99.99 || (this.lowValue2 >= this.highValue2)
                    || this.lowValue2 === null || this.highValue2 === null
                )
            ) {
                this.$message({ type: 'error', message: '阀值设置有误！！' });
                return;
            } else if (channel === "19" &&
                (this.lowValue3 < 0 || this.lowValue3 > 99
                    || this.highValue3 <= 0 || this.highValue3 > 99.99 || (this.lowValue3 >= this.highValue3)
                    || this.lowValue3 === null || this.highValue3 === null
                )
            ) {
                this.$message({type: 'error',message: '阀值设置有误！！'});
                return;
            }
            let scaleStr;
            if (channel === "11") {
                let low = this.lowValue1 * 100;
                let high = this.highValue1 * 100;
                scaleStr = low + "-" + high;
            } else if (channel === "15") {
                let low = this.lowValue2 * 100;
                let high = this.highValue2 * 100;
                scaleStr = low + "-" + high;
            } else {
                let low = this.lowValue3 * 100;
                let high = this.highValue3 * 100;
                scaleStr = low + "-" + high;
            }
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的电阻阀值吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleSetScale1(channel , scaleStr , deviceVoss[i])
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info',message: '操作已取消'});
                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的电阻阀值吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleSetScale1(channel , scaleStr , this.deviceVo)
                }).catch(() => {
                    this.$message({type: 'info',message: '操作已取消'});
                });
            }
        },
        closeDialog() {
            MyCloseDialog();
        },
        handleSetWorkTime() {
            if (this.startTime1 === null
                || this.startTime2 === null
                || this.startTime3 === null
                || this.endTime1 === null
                || this.endTime2 === null
                || this.endTime3 === null
                || this.endTime1 < this.startTime1
                || this.endTime2 < this.startTime2
                || this.endTime3 < this.startTime3
            ) {
                this.$message({ type: 'error', message: '时间设置有误！！' });
                return;
            }
            if (this.line_radio === "1") {
                this.$confirm("你确定要设置终端 " + this.deviceVo.stationId + "的工作时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleSetWorkTime1(this.deviceVo)
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要设置生产线 " + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName + "的工作时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleSetWorkTime1(deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        handleGetWorkTime() {
            $axios({
                url: "/resistance/search/old/getWorkTime",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: "获取工作时间成功！！" });
                    this.startTime1 = new Date("2016-09-10T" + res.data.tdkssj);
                    this.startTime2 = new Date("2016-09-10T" + res.data.rtkssj);
                    this.startTime3 = new Date("2016-09-10T" + res.data.sbkssj);
                    this.endTime1 = new Date("2016-09-10T" + res.data.tdjssj);
                    this.endTime2 = new Date("2016-09-10T" + res.data.rtjssj);
                    this.endTime3 = new Date("2016-09-10T" + res.data.sbjssj);
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        // 校正时间的请求方法
        handleTime() {
            if (this.line_radio === "1") {
                this.$confirm("你确定要校正终端 " + this.deviceVo.stationId + "的时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleTime1(this.deviceVo) ;
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要校正生产线 " + this.deviceVo.line + "所有 " + this.deviceVo.deviceTypeName
                    + " 的时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleTime1(deviceVoss[i]) ;
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        handleScreenOn(status){
            let op = '' ;
            if (status === "00") {
                op = "关闭";
            } else if (status === "01") {
                op = "开启";
            }
            if (this.line_radio === "1") {
                this.$confirm("你确定要" + op + "终端 " + this.deviceVo.stationId + "的屏幕吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleScreenOn1(status,this.deviceVo) ;
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要" + op + "生产线 " + this.deviceVo.line + "所有 " + this.deviceVo.deviceTypeName
                    + " 的屏幕吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleScreenOn1(status,deviceVoss[i]) ;
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        // 处理信道的请求方法
        handleXindao() {
            this.$confirm("你确定要更改终端 " + this.deviceVo.stationId + "的信道吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: "/resistance/operation/old/setSignalChannel/" + this.change_gatewayId,
                    method: 'post',
                    data: this.deviceVo
                }).then((res) => {
                    if (res.code === 0) {
                        this.$message({ type: 'success', message: res.msg });
                        this.operationFormVisible = false;
                        this.findPage();
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            }).catch(() => {
                this.$message({ type: 'info', message: '操作已取消' });
            });
        },
        handleSound(status) {
            let ss = "";
            if (status === "00") {
                ss = "打开";
            } else if (status === "01") {
                ss = "关闭";
            }
            this.$confirm("你确定要" + ss + "终端 " + this.deviceVo.stationId + "的声音吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: "/resistance/operation/old/soundOn/" + status,
                    method: 'post',
                    data: this.deviceVo
                }).then((res) => {
                    if (res.code === 0) {
                        this.$message({ type: 'success', message: res.msg });
                    } else {
                        this.$message.error(res.msg);
                    }
                })
            }).catch(() => {
                this.$message({type: 'info',message: '操作已取消'});
            });
        },
        handleSelectionChange(val) {
            this.multipleSelection = [];
            for (let i = 0; i < val.length; i++) {
                this.multipleSelection.push(val[i].deviceId);
            }
        },
        // 当网关被选中是触发事件
        handleSelectChange(value) {
            for (const gateway of this.gateways) {
                if (value === gateway.gatewayId) {
                    this.formData.signalChannel = gateway.signalChannel;
                }
            }
        },
        batchDelete() {
            if (this.multipleSelection.length <= 0) {
                this.$message.error("未选中任何数据!");
                return;
            }
            this.$confirm("你确定要删除所选中的数据吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: '/device/batchDelete',
                    method: 'post',
                    data: this.multipleSelection
                }).then((res) => {
                    if (res.code === 0){
                        this.findPage();
                        this.$message.success(res.msg);
                    }else {
                        this.$message.error(res.msg);
                    }
                    
                })
            }).catch(() => {
                this.$message({type: 'info',message: '操作已取消'});
            });
        },
        emptySearch() {
            this.pagination = {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                stationId: null, //查询条件
                position: null, //查询条件
                deviceTypeId: null,
                lineId: null,
            }
            this.findPage();
        },
        saveOrUpdate(){
            if(this.editTitle == "添加终端信息"){
                this.handleAdd();
            }else if(this.editTitle == "编辑终端信息"){
                this.handleEdit();
            }
        },
        //编辑
        handleEdit() {
            let num = +this.formData.stationId;
            if (isNaN(num) || num > 4294967295) {
                this.$message.error("终端ID包含非数字字符或超出了范围!");
            } else {
                //进行表单校验
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        this.formData.channelTypes = [];
                        //表单校验通过，发生ajax请求，将录入的数据提交到后台进行处理
                        let flag = false ;
                        for (let i = 0; i < this.channelNumber; i++) {
                            flag = flag || this.channels[i].enabled ;
                            this.formData.channelTypes.push({
                                channelTypeId: this.channels[i].channelTypeId,
                                enabled: this.channels[i].enabled ,
                                position: this.channels[i].position ,
                                deviceType: this.$refs.deviceTypeSel.selected.label ,
                            })
                        }
                        if (!flag) {
                            this.$message.error("请至少启用一个信道! 否则请删除该终端。");
                            return;
                        }
                        this.formData.stationId = this.formData.stationId.trim();
                        this.formData.position = this.formData.position.trim();
                        $axios({
                            url: '/device/updateDevice',
                            method: 'post',
                            data: this.formData
                        }).then((res) => {
                            if (res.code === 0){
                                this.$message.success(res.msg);
                            }else {
                                this.$message.error(res.msg);
                            }
                            
                        }).finally(() => {
                            this.findPage();
                            this.dialogFormVisible = false;
                        });
                    } else {
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            }
        },
        //添加
        handleAdd() {
            let num = +this.formData.stationId;
            if (isNaN(num) || num > 4294967295) {
                this.$message.error("终端ID包含非数字字符或超出了范围!");
            } else {
                //进行表单校验
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        this.formData.channelTypes = [];
                        let flag = false ;
                        //表单校验通过，发生ajax请求，将录入的数据提交到后台进行处理
                        for (let i = 0; i < this.channelNumber; i++) {
                            flag = flag || this.channels[i].enabled ;
                            this.formData.channelTypes.push({
                                channelTypeId: this.channels[i].channelTypeId,
                                enabled: this.channels[i].enabled ,
                                position: this.channels[i].position ,
                                deviceType: this.$refs.deviceTypeSel.selected.label ,
                            })
                        }
                        if (!flag) {
                            this.$message.error("请至少启用一个信道!");
                            return;
                        }
                        this.formData.stationId = this.formData.stationId.trim();
                        this.formData.position = this.formData.position.trim();
                        $axios({
                            url: '/device/addDevice',
                            method: 'post',
                            data: this.formData
                        }).then((res) => {
                            if (res.code === 0){
                                this.findPage();
                                this.dialogFormVisible = false;
                                this.$message.success(res.msg);
                            }else {
                                this.$message.error(res.msg);
                            }
                            
                        })
                    } else {
                        //校验不通过
                        this.$message.error("数据校验失败，请检查你的输入信息是否正确！");
                        return false;
                    }
                });
            }
        },
        //分页查询
        findPage() {
            $axios({
                url: '/device/selectDevicePage',
                method: 'post',
                data: this.pagination
            }).then((res) => {
                if (res.code === 0){
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.items;
                }else {
                    this.$message.error(res.msg);
                }
                
            })
        },
        // 弹出添加窗口
        handleCreate() {
            //弹出新增窗口
            this.dialogFormVisible = true;
            this.formData = {};//重置数据
            for (let i = 0; i < 6; i++) {
                this.channels[i].channelTypeId = null;
                this.channels[i].enabled = true;
                this.channels[i].position = null;
                this.channels[i].deviceType = null;
            }
            this.channelNumber = 1;
            this.editTitle = "添加终端信息" ;
        },
        // 弹出编辑窗口
        handleUpdate(row) {
            this.editTitle = "编辑终端信息" ;
            for (let i = 0; i < 6; i++) {
                this.channels[i].channelTypeId = null;
                this.channels[i].enabled = true;
            }
            //弹出编辑窗口
            this.dialogFormVisible = true;
            $axios({
                url: '/device/selectById/' + row.deviceId,
                method: 'get',
                params: null
            }).then((res) => {
                if (res.code === 0){
                    this.formData = res.data;
                    this.channelNumber = res.data.channelTypes.length ;
                    for (let i = 0; i < this.channelNumber; i++) {
                        this.channels[i].channelTypeId = res.data.channelTypes[i].channelTypeId;
                        this.channels[i].enabled = res.data.channelTypes[i].enabled;
                        this.channels[i].position = res.data.channelTypes[i].position;
                    }
                }else {
                    this.$message.error(res.msg);
                }
                
            })
        },
        enabledMon(id , value){
            let str = (value===0)?"关闭":"开启" ;
            $axios({
                url: '/device/enabledMon/' + id + "/" + value,
                method: 'get',
                params: null
            }).then((res) => {
                if (res.code === 0){
                    this.$message.success(str + "监控成功！！");
                    this.findPage();
                }else {
                    this.$message.error(str + "监控失败！！");
                }
                
            })
        },
        cancelOpt() {
            //关闭新增窗口
            this.dialogFormVisible = false;
            this.formData = {};
            this.$message("已取消操作！！");
        },        
        handleOperation(row) {
            handleOperation1(row);
        },
        //切换页码
        handleCurrentChange(currentPage) {
            this.pagination.currentPage = currentPage;
            this.findPage();
        },
        handleSizeChange(pageSize) {
            this.pagination.pageSize = pageSize;
            this.findPage() ;
        },
        handleDelete(row) {
            this.$confirm("你确定要删除当前数据吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: '/device/deleteDevice/' + row.deviceId,
                    method: 'delete',
                    data: null
                }).then((res) => {
                    if (res.code === 0){
                        this.$message({ type: 'success', message: res.msg });
                        this.findPage();
                    }else {
                        this.$message.error(res.msg);
                    }
                    
                })
            }).catch(() => {
                this.$message({ type: 'info', message: '操作已取消' });
            });
            
        },
        showServer(item) {
            return item.gatewayName + "  信道:" + item.signalChannel + " Ip地址:" + item.serverIp;
        },

        // =============温湿度测量仪操作方法=============
        handleTemTime() {
            $axios({
                url: "/temAndHum/setTime",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        getTemScale(){
            $axios({
                url: "/temAndHum/getTemUpperAndLower",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                console.log(res.data);
                if (res.code === 0) {
                    this.temUpper = res.data.temUpper ;
                    this.temLower = res.data.temLower ;
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        getHumiScale(){
            $axios({
                url: "/temAndHum/getHumiUpperAndLower",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.humiUpper = res.data.humiUpper ;
                    this.humiLower = res.data.humiLower ;
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        temClick(status){
            $axios({
                url: "/temAndHum/temClick/" + status,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        humiClick(status){
            $axios({
                url: "/temAndHum/humiClick/" + status,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        
        setTemScale(){
            if(this.temUpper == null || this.temUpper == null ){
                this.$message.error("温度上限或湿度下限不能为空！");
                return ;
            }
            if(this.temUpper<0 || this.temLower<=0){
                this.$message.error("温度上限或温度下限不能小于0！");
                return ;
            }
            let arr1 = (this.temUpper + '').split(".") ;
            let arr2 = (this.temLower + '').split(".") ;
            if(arr1.length == 2 && arr1[1].length>1){
                this.$message.error("温度上限请填入数字（小数点后小于等于一位）！");
                return ;
            }
            if(arr2.length == 2 && arr2[1].length>1){
                this.$message.error("温度下限请填入数字（小数点后小于等于一位）！");
                return ;
            }
            if(this.temUpper<=this.temLower){
                this.$message.error("温度上限不能小于等于温度下限！");
                return ;
            }
            let temStr = (this.temLower*10) + "-" + (this.temUpper*10) ;
            $axios({
                url: "/temAndHum/setTemUpperAndLower/" + temStr,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        setHumiScale(){
            if(this.humiUpper == null || this.humiLower == null ){
                this.$message.error("湿度上限或湿度下限不能为空！");
                return ;
            }
            if(this.humiUpper<0 || this.humiLower<=0){
                this.$message.error("湿度上限或湿度下限不能小于0！");
                return ;
            }
            let arr1 = (this.humiUpper + '').split(".") ;
            let arr2 = (this.humiLower + '').split(".") ;
            if(arr1.length == 2 && arr1[1].length>1){
                this.$message.error("湿度上限请填入数字（小数点后小于等于一位）！");
                return ;
            }
            if(arr2.length == 2 && arr2[1].length>1){
                this.$message.error("湿度下限请填入数字（小数点后小于等于一位）！");
                return ;
            }
            if(this.humiUpper<=this.humiLower){
                this.$message.error("湿度上限不能小于等于湿度下限！");
                return ;
            }
            let humiStr = (this.humiLower*10) + "-" + (this.humiUpper*10) ;
            $axios({
                url: "/temAndHum/setHumiUpperAndLower/" + humiStr,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        getTemDetail(){
            $axios({
                url: "/temAndHum/geTemDetail" ,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.temDetail = res.data ;
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },

        // ===========================新版接地电阻仪============================
        newCheckTime(){
            if (this.line_radio === "1") {
                this.$confirm("你确定要校正终端 " + this.deviceVo.stationId + "的时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleTime2(this.deviceVo) ;
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要校正生产线 " + this.deviceVo.line + "所有 " + this.deviceVo.deviceTypeName
                    + " 的时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleTime2(deviceVoss[i]) ;
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        newSoundOn(){
            $axios({
                url: "/resistance/operation/soundOn/01",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            });
        },
        newLockKey(status){
            if (this.line_radio === "1") {
                this.$confirm("你确定要锁定或解锁终端 " + this.deviceVo.stationId + "的按键吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    newLockKey1(this.deviceVo , status) ;
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要锁定或解锁生产线 " + this.deviceVo.line + "所有 " + this.deviceVo.deviceTypeName
                    + " 的按键吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                newLockKey1(deviceVoss[i] , status) ;
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        checkRedClock(){
            $axios({
                url: "/resistance/search/checkRedClock",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.redClock = res.data ;
                } else {
                    this.$message.error("查询失败！！");
                }
            });
        },
        newInfraredOn(status){
            if (this.line_radio === "1") {
                this.$confirm("你确定要开启或关闭 " + this.deviceVo.stationId + "的红外感应功能吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    newInfraredOn1(this.deviceVo , status) ;
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要开启或关闭生产线 " + this.deviceVo.line + "所有 " + this.deviceVo.deviceTypeName
                    + " 的红外感应功能吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                newInfraredOn1(deviceVoss[i], status) ;
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info', message: '操作已取消'});
                });
            }
        },
        newXindao() {
            this.$confirm("你确定要更改终端 " + this.deviceVo.stationId + "的信道吗？", "提示", {//确认框
                type: 'warning'
            }).then(() => {
                $axios({
                    url: "/resistance/operation/setSignalChannel/" + this.change_gatewayId,
                    method: 'post',
                    data: this.deviceVo
                }).then((res) => {
                    if (res.code === 0) {
                        this.$message({ type: 'success', message: res.msg });
                        this.findPage();
                        this.operationFormVisible_NewDZY = false;
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            }).catch(() => {
                this.$message({ type: 'info', message: '操作已取消' });
            });
        },
        handleSetScaleNew(channelType) {
            if (channelType === "1C" &&
                (this.lowValue1 < 0 || this.lowValue1 > 99
                    || this.highValue1 <= 0 || this.highValue1 > 100 || (this.lowValue1 >= this.highValue1)
                    || this.lowValue1 === null || this.highValue1 === null
                )
            ) {
                this.$message({ type: 'error',  message: '设备阀值设置有误！！' });
                return;
            } else if (channelType === "20" &&
                (this.lowValue2 < 0 || this.lowValue2 > 99
                    || this.highValue2 <= 0 || this.highValue2 > 100 || (this.lowValue2 >= this.highValue2)
                    || this.lowValue2 === null || this.highValue2 === null
                )
            ) {
                this.$message({ type: 'error', message: '台垫阀值设置有误！！' });
                return;
            } else if (channelType === "24" &&
                (this.lowValue3 < 0 || this.lowValue3 > 99
                    || this.highValue3 <= 0 || this.highValue3 > 100 || (this.lowValue3 >= this.highValue3)
                    || this.lowValue3 === null || this.highValue3 === null
                )
            ) {
                this.$message({type: 'error',message: '人体阀值设置有误！！'});
                return;
            }
            let scaleStr;
            if (channelType === "1C") {
                let low = this.lowValue1 * 10;
                let high = this.highValue1 * 10;
                scaleStr = low + "-" + high;
            } else if (channelType === "20") {
                let low = this.lowValue2 * 10;
                let high = this.highValue2 * 10;
                scaleStr = low + "-" + high;
            } else {
                let low = this.lowValue3 * 10;
                let high = this.highValue3 * 10;
                scaleStr = low + "-" + high;
            }
            if (this.line_radio === "2") {
                this.$confirm("你确定要设置生产线" + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName
                    + "的电阻阀值吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleSetScale2(channelType , scaleStr , deviceVoss[i])
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({type: 'info',message: '操作已取消'});
                });
            } else {
                this.$confirm("你确定要设置终端" + this.deviceVo.stationId
                    + "的电阻阀值吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleSetScale2(channelType , scaleStr , this.deviceVo)
                }).catch(() => {
                    this.$message({type: 'info',message: '操作已取消'});
                });
            }
        },
        handleGetScaleNew(channelType) {
            $axios({
                url: "/resistance/search/getScale/" + channelType,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({type: 'success',message: res.msg});
                    if(channelType == "1C"){
                        this.lowValue1 = res.data.data.lowerNum;
                        this.highValue1 = res.data.data.upperNum;
                    }else if (channelType == "20"){
                        this.lowValue2 = res.data.data.lowerNum;
                        this.highValue2 = res.data.data.upperNum;
                    }else{
                        this.lowValue3 = res.data.data.lowerNum;
                        this.highValue3 = res.data.data.upperNum;
                    }
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleGetWorkTimeNew(channelType) {
            $axios({
                url: "/resistance/search/getWorkTime/" + channelType,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: "获取工作时间成功！！" });
                    if(channelType == "28"){
                        this.startTime1 = new Date("2016-09-10T" + res.data.data.timeStart);
                        this.endTime1 = new Date("2016-09-10T" + res.data.data.timeEnd);
                    }else if(channelType == "2E"){
                        this.startTime2 = new Date("2016-09-10T" + res.data.data.timeStart);
                        this.endTime2 = new Date("2016-09-10T" + res.data.data.timeEnd);
                    }else{
                        this.startTime3 = new Date("2016-09-10T" + res.data.data.timeStart);
                        this.endTime3 = new Date("2016-09-10T" + res.data.data.timeEnd);
                    }
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleSetWorkTimeNew(channelType) {
            if (channelType== '28')
            {
                if( this.startTime1 === null
                    || this.endTime1 === null
                    || this.endTime1 < this.startTime1
                ){
                    this.$message({ type: 'error', message: '时间设置有误！！' });
                    return;
                }
            }else if (channelType== '2E')
            {
                if( this.startTime2 === null
                    || this.endTime2 === null
                    || this.endTime2 < this.startTime2
                ){
                    this.$message({ type: 'error', message: '时间设置有误！！' });
                    return;
                }
            }else{
                if( this.startTime3 === null
                    || this.endTime3 === null
                    || this.endTime3 < this.startTime3
                ){
                    this.$message({ type: 'error', message: '时间设置有误！！' });
                    return;
                }
            }
            if (this.line_radio === "1") {
                this.$confirm("你确定要设置终端 " + this.deviceVo.stationId + "的工作时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    handleSetWorkTime2( channelType, this.deviceVo)
                }).catch((e) => {
                    console.log(e);
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            } else {
                this.$confirm("你确定要设置生产线 " + this.deviceVo.line + "所有" + this.deviceVo.deviceTypeName + "的工作时间吗？", "提示", {//确认框
                    type: 'warning'
                }).then(() => {
                    $axios({
                        url: "/device/getByLineAndType?deviceType=" + this.deviceVo.deviceTypeName + "&lineName=" + this.deviceVo.line,
                        method: 'get',
                        params: null
                    }).then((res) => {
                        if (res.code === 0) {
                            let deviceVoss = res.data;
                            for (let i = 0; i < deviceVoss.length; i++) {
                                handleSetWorkTime2(channelType , deviceVoss[i]);
                            }
                        } else {
                            this.$message.error("查询失败！！");
                        }
                    });
                }).catch(() => {
                    this.$message({ type: 'info', message: '操作已取消' });
                });
            }
        },
        getDetailsNew() {
            $axios({
                url: "/resistance/search/getDetails",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.dzyDetailNew = res.data ;
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        searchChOn(){
            $axios({
                url: "/resistance/search/searchChannelEnabled",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.channelOnDT = res.data ;
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        checkChOn(){
            $axios({
                url: "/resistance/search/checkChOn",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type: 'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        changeChOn(value){
            let num = this.channelOnDT.nowNum + value ;
            $axios({
                url: "/resistance/operation/channelOn/" + num ,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    axios.post("/resistance/search/searchChannelEnabled", this.deviceVo).then((res) => {
                        if (res.data.code === 0) {
                            this.channelOnDT = res.data.data ;
                        } else {
                            this.$message.error(res.data.msg);
                        }
                    });
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        searchChTypes(){
            $axios({
                url: "/resistance/search/searchChannelType",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.channelTypeList = res.data ;
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        checkChTypes(){
            $axios({
                url: "/resistance/search/checkChTypes",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        changeChType(ch){
            let chType ;
            if(ch == "0A"){
                chType = this.channelTypeList.ch1;
            }else if(ch == "0B"){
                chType = this.channelTypeList.ch2;
            }else if(ch == "0C"){
                chType = this.channelTypeList.ch3;
            }else{
                chType = this.channelTypeList.ch4;
            }
            $axios({
                url: "/resistance/operation/setChannelType/" + chType + "/" + ch,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        //================= 新版接地电阻仪结束 ==================
        getDustStatus(){
            $axios({
                url: "/dust/searchDetail",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.dustStatus = res.data ;
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        simpleOn(value){
            $axios({
                url: "/dust/samplingOn/" + value,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        dustClockOn(value){
            $axios({
                url: "/dust/dustClockOn/" + value,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        getChannelValue(){
            $axios({
                url: "/dust/getChannelValue",
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                    this.channelValue = res.data ;
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        setChannelValue(channel , value){
            $axios({
                url: "/dust/setChannelValue/" + channel + "/" + value,
                method: 'post',
                data: this.deviceVo
            }).then((res) => {
                if (res.code === 0) {
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleSort(){
            this.sortFlag = true;
        },
        searchSortData(){
            if (this.sortLineId == null || this.sortLineId == ""){
                this.$message({ type: 'error', message: '请先选择要排序的生产线！！' });
                return;
            }
            $axios({
                url: "/device/getSortDeviceList/"+this.sortLineId,
                method: 'get',
                params: null
            }).then((res) => {
                if (res.code === 0) {
                    this.sortDeviceList = res.data ;
                    this.sortLength = res.data.length ;
                    this.$message.success(res.msg);
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleSortUp(index){
            stationId1 = this.sortDeviceList[index].stationId
            stationId2 = this.sortDeviceList[index-1].stationId
            $axios({
                url: "/device/sortDevice/"+stationId1 + "/" + stationId2,
                method: 'get',
                params: null
            }).then((res) => {
                if (res.code === 0) {
                    this.sortDeviceList = res.data ;
                    this.sortLength = res.data.length ;
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        handleSortDown(index){
            stationId1 = this.sortDeviceList[index].stationId ;
            stationId2 = this.sortDeviceList[index+1].stationId ;
            $axios({
                url: "/device/sortDevice/"+stationId1 + "/" + stationId2,
                method: 'get',
                params: null
            }).then((res) => {
                if (res.code === 0) {
                    this.sortDeviceList = res.data ;
                    this.sortLength = res.data.length ;
                    this.$message({ type:'success', message: res.msg });
                } else {
                    this.$message.error(res.msg);
                }
            })
        }
    }
});